package com.gm.task;

import com.gm.model.po.Card;
import com.gm.service.user.CardService;
import com.gm.service.user.TaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/6/28.
 */

@Component
@EnableScheduling
public class BillTask {
    private static  final Logger logger = LoggerFactory.getLogger(BillTask.class);
    @Autowired
    protected TaskService taskService;
    @Autowired
    protected CardService cardService;

    //@Scheduled(cron="0 0 1  * * ? ") //每天凌晨1点执行一次
    //@Scheduled(cron="0/1000 * *  * * ? ") //每10秒执行一次
    @Scheduled(cron="0 */10 * * * ?") //每10秒执行一次
    public void test(){
        SimpleDateFormat sf = new SimpleDateFormat("dd");
        String now = sf.format(new Date());

        List<Card> cardList = cardService.getAllCardByNow(Integer.valueOf(now));
        if(cardList.size()==0){
            logger.info("{}日无可以执行任务",now);
        }else{
            taskService.opertationTask(cardList);
            logger.info("{}日定时任务执行了.............",now);
        }
    }

}
